<template>
  <button 
    class="random-button"
    :class="{ 'is-rotating': isRotating }"
    @click="handleClick"
    :disabled="isRotating"
  >
    <span class="button-content">
      <span v-if="!isRotating">{{ buttonText }}</span>
      <span v-else class="loading-text">
        <svg class="loading-icon" viewBox="0 0 24 24">
          <circle class="path" cx="12" cy="12" r="10" fill="none" stroke-width="2"></circle>
        </svg>
        抽取中...
      </span>
    </span>
  </button>
</template>

<script>
export default {
  name: 'RandomButton',
  props: {
    buttonText: {
      type: String,
      default: '随机抽吃啥'
    },
    isRotating: {
      type: Boolean,
      default: false
    }
  },
  emits: ['randomize'],
  methods: {
    handleClick() {
      this.$emit('randomize');
    }
  }
}
</script>

<style scoped>
.random-button {
  position: relative;
  padding: 20px 40px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 50px;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 10px 25px -5px rgba(102, 126, 234, 0.5);
  overflow: hidden;
  user-select: none;
}

.random-button::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.random-button:hover {
  transform: translateY(-3px) scale(1.05);
  box-shadow: 0 15px 30px -5px rgba(102, 126, 234, 0.7);
}

.random-button:hover::before {
  opacity: 1;
}

.random-button:active {
  transform: translateY(-1px) scale(0.98);
  box-shadow: 0 10px 25px -5px rgba(102, 126, 234, 0.5);
}

.random-button:disabled {
  cursor: not-allowed;
  opacity: 0.8;
}

.random-button.is-rotating {
  transform: scale(0.95);
  box-shadow: 0 5px 15px -5px rgba(102, 126, 234, 0.5);
  animation: pulse 1.5s ease-in-out infinite;
}

.random-button.is-rotating::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  transform: translate(-50%, -50%);
  animation: ripple 1.5s ease-out infinite;
}

@keyframes pulse {
  0%, 100% {
    transform: scale(0.95);
    box-shadow: 0 5px 15px -5px rgba(102, 126, 234, 0.5);
  }
  50% {
    transform: scale(1);
    box-shadow: 0 10px 25px -5px rgba(102, 126, 234, 0.8);
  }
}

@keyframes ripple {
  0% {
    width: 0;
    height: 0;
    opacity: 0.5;
  }
  100% {
    width: 300px;
    height: 300px;
    opacity: 0;
  }
}

.button-content {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.loading-icon {
  width: 24px;
  height: 24px;
  animation: rotate 1s linear infinite;
}

.path {
  stroke: currentColor;
  stroke-dasharray: 50;
  stroke-dashoffset: 50;
  animation: dash 1.2s ease-in-out infinite;
  stroke-linecap: round;
}

@keyframes rotate {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@keyframes dash {
  0% {
    stroke-dashoffset: 50;
  }
  50% {
    stroke-dashoffset: 10;
    transform: rotate(135deg);
  }
  100% {
    stroke-dashoffset: 50;
    transform: rotate(360deg);
  }
}

.loading-text {
  animation: bounce 1.5s ease-in-out infinite;
  display: flex;
  align-items: center;
  gap: 10px;
}

@keyframes bounce {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-3px);
  }
}

/* 响应式设计 */
@media (max-width: 768px) {
  .random-button {
    padding: 16px 32px;
    font-size: 16px;
    border-radius: 40px;
  }
  
  .random-button:hover {
    transform: translateY(-2px) scale(1.03);
  }
  
  .random-button:active {
    transform: translateY(-1px) scale(0.97);
  }
  
  .loading-icon {
    width: 20px;
    height: 20px;
  }
}

@media (max-width: 480px) {
  .random-button {
    padding: 14px 28px;
    font-size: 15px;
    border-radius: 35px;
  }
  
  .loading-icon {
    width: 18px;
    height: 18px;
  }
}
</style>